package cn.smartorigin.soas.frame.menubar;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JMenu;
import javax.swing.border.Border;

import cn.smartorigin.soas.frame.SoasUtil;

public class CellMenu extends JMenu{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Color backgroundColor = SoasUtil.MENUITEM_BACKGROUND;
    private Color foregroundColor = SoasUtil.DEFAULT_TEXT_COLOR;
    private int borderThickness = 1;
    private Border border = BorderFactory.createLineBorder(backgroundColor, borderThickness);
    private int preferredHeight = 25;
    
    public CellMenu() {
        init();
    }
	
    public CellMenu(Action a) {
		super(a);
		init();
	}

	public CellMenu(String s, boolean b) {
		super(s, b);
		init();
	}

	public CellMenu(String s) {
		super(s);
		init();
	}

	private void init(){
        this.setForeground(foregroundColor);
        this.setFont(SoasUtil.FONT_12_BOLD);
        this.setOpaque(false);
        this.setBackground(backgroundColor);
        this.setBorder(border);
	}
	
    @Override
    protected void paintComponent(Graphics g) {

        if (this.isSelected()) {
            Graphics2D g2d = (Graphics2D) g;
            g2d.setColor(SoasUtil.MENUITEM_SELECTED_BACKGROUND);
            g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
            super.paintComponent(g);
        } else {
            super.paintComponent(g);
        }
    }
    
    @Override
    public Dimension getPreferredSize() {
        return new Dimension(super.getPreferredSize().width, preferredHeight);
    }

    
}
